using System;
using Gtk;
using System.Diagnostics;
using MaplinRobotArm;
using System.Threading;

public partial class MainWindow : Gtk.Window
{
	private RobotArm theRobotArm = null;
	
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		theRobotArm = new RobotArm();
		
		int width,height;
		GetSize(out width,out height);
		
		if( theRobotArm.Ok )
		{
			this.Title = "Robot arm connected";
		}
		else
		{
			this.Title = "Robot arm not found";
		}
	}

	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
		theRobotArm.Dispose();
	}
	
	protected virtual void AllStop (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0,0,0);
	}
	
	protected virtual void GripperOpen (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x02,0,0);
	}
			
	protected virtual void GripperClose (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x01,0,0);
	}
	
	protected virtual void WristUp (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x04,0,0);
	}
	
	protected virtual void WristDown (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x08,0,0);
	}
	
	protected virtual void ElbowUp (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x10,0,0);
	}
	
	protected virtual void ElbowDown (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x20,0,0);
	}
	
	protected virtual void ShoulderUp (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x40,0,0);
	}
	
	protected virtual void ShoulderDown (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x80,0,0);
	}
	
	protected virtual void BaseLeft (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0,0x02,0);
	}
	
	protected virtual void BaseRight (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0,0x01,0);
	}
	
	protected virtual void OnSizeRequested (object o, Gtk.SizeRequestedArgs args)
	{
	}
	
	protected virtual void MoveOut (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x10,0,0);
		Thread.Sleep(300);
		theRobotArm.SendData(0x90,0,0);
	}
	
	protected virtual void MoveIn (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x10,0,0);
		Thread.Sleep(300);
		theRobotArm.SendData(0x60,0,0);
	}
	
	protected virtual void PickUp (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0x54,0,0);
	}
	
	protected virtual void PutDown (object sender, System.EventArgs e)
	{
		theRobotArm.SendData(0xA8,0,0);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

